Skip to content

Conversation

@itsmeichigo
Copy link
Contributor

@itsmeichigo itsmeichigo commented Aug 6, 2025

Part of WOOMOB-965

Description

This PR updates the connection steps of the Jetpack setup flow to use the connection API following the guides in pe5sF9-401-p2.

Most of the line changes come from the unit tests. Tracking will be updated in a separate PR.

Testing steps

Follow test plan in pe5sF9-42S-p2.

Testing edge case with JCP site

  1. Use a website with WooCommerce but no Jetpack.
  2. Have two wp-admin accounts UserA and UserB, and two WordPress.com accounts WPComA and WPComB.
  3. Install and activate Woo Shipping plugin the the site.
  4. From Woo Shipping settings, connect the site to the WordPress.com account WPComA using the user UserA.
  5. On the app, sign in to the website using WPComB.
  6. Confirm that an error screen is displayed saying the site is connected to a different account.
  7. Select Connect Jetpack and use UserB site credentials for the setup.
  8. Confirm that the app handles the connection natively without a WebView.
  9. Once done, confirm that you are logged in to the app using the WordPress.com WPComB.
  10. You should still see the Jetpack benefit banner at the bottom of My Store screen. This is because the setup step only connects the user with Jetpack connection package. Jetpack plugin is still missing.
  11. (Optional) Tap on the Jetpack benefit banner to install the plugin. Confirm that after installation and activation complete, the app is reloaded and can receive push notifications.

Testing information

  • Verified the test plan and edge case using simulator iPhone 16 iOS 18.2
  • Could not follow the guide in TC7 (asking for confirmation here pe5sF9-42S-p2#comment-4689). For this case, I used Proxyman to remove isRegistered in the response of GET jetpack/v4/connection/data instead.

Screenshots

Basic flow:

Simulator.Screen.Recording.-.iPhone.16.-.2025-08-07.at.15.43.21.mp4

Edge case for JCP sites when logged with wrong account:

Simulator.Screen.Recording.-.iPhone.16.-.2025-08-08.at.15.03.39.mp4

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@itsmeichigo itsmeichigo added this to the 23.0 milestone Aug 6, 2025
@itsmeichigo itsmeichigo added type: task An internally driven task. category: jetpack Specific to Jetpack sites. labels Aug 6, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Aug 6, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Numberpr15983-29929d7
Version23.0
Bundle IDcom.automattic.alpha.woocommerce
Commit29929d7
Installation URL10du9el2lbcp8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@itsmeichigo itsmeichigo modified the milestones: 23.0, 23.1 Aug 7, 2025
Base automatically changed from woomob-965-yosemite-update to trunk August 7, 2025 07:39
@itsmeichigo itsmeichigo marked this pull request as ready for review August 7, 2025 11:04
@itsmeichigo itsmeichigo marked this pull request as draft August 8, 2025 04:10
@itsmeichigo itsmeichigo removed the request for review from RafaelKayumov August 8, 2025 04:11
Comment on lines -323 to -327
/// Jetpack setup will fail anyway without admin role, so check that first.
let roles = stores.sessionManager.defaultRoles
guard roles.contains(.administrator) else {
throw JetpackCheckError.missingPermission
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant because fetchJetpackConnectionData will throw permission error if needed. This error is thrown if the user role is shop manager and the site is not registered with WPCom yet.

@itsmeichigo itsmeichigo marked this pull request as ready for review August 8, 2025 10:29
Copy link
Contributor

@RafaelKayumov RafaelKayumov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Followed the testing plan including the edge case with WP com connecting through shipping plugin. Works as described.

I'm still not too fluent with the Jetpack connection flow described in pe5sF9-401-p2. Code-wise looks good.

Left just 1 nit. Also a couple times I saw that the app was returning to the Login screen after entering store login/password and triggering login. Wasn't able to reproduce it on purpose.

Comment on lines +23 to +27
public init(userId: Int64, scope: String, secret: String) {
self.userId = userId
self.scope = scope
self.secret = secret
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rely on the synthesized initializer in this case? Looks like the manual init does the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to explicitly add this initializer as I need it in JetpackSetupViewModelTests on the UI layer. The initializer needs to be public to be accessed from outside of the Networking module.

@itsmeichigo
Copy link
Contributor Author

itsmeichigo commented Aug 11, 2025

Also a couple times I saw that the app was returning to the Login screen after entering store login/password and triggering login. Wasn't able to reproduce it on purpose.

I can see this as well. The reason behind this is the failure to generate application password even though login/password authentication was successful. This happens quite arbitrarily from my experience, I'm unsure if it's only an issue with Jurassic Ninja sites. Anyway, it's not relevant to the changes in this PR I believe.

Updated: I managed to consistently reproduce the issue:

  1. Log in to a JN test site using application password.
  2. Connect Jetpack through the app.
  3. Log out of the app.
  4. Disconnect Jetpack on a web browser.
  5. Log back in with site credentials -> application password generation fails.

I logged this issue in WOOMOB-1018. Merging this PR for now.

@itsmeichigo itsmeichigo merged commit dc9cf5c into trunk Aug 11, 2025
14 checks passed
@itsmeichigo itsmeichigo deleted the woomob-965-jetpack-connection-update branch August 11, 2025 08:27
Comment on lines +452 to +456
guard let wpcomCredentials, case .wpcom = wpcomCredentials else {
/// WPCom credentials are necessary to finalize connection through API
/// If this is unavailable, fall back to the web flow.
return startConnectionWithWebView()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsmeichigo just a question about this part and the comment there, is there a case where we might reach this screen without WPCom credentials?

On Android, we don't have any check like this, and I looked into the iOS code, and it seems to me the only place where we pass an Optional value for the credentials is here, where it seems the credentials would be necessarly present.

WDYT about this? If I'm right in my above remark, should we try to make the field in the ViewModel not optional to avoid any confusing because of this above check and comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @hichamboushaba. I added the change in #16001.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: jetpack Specific to Jetpack sites. type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants